// explosion.js
class Explosion extends Phaser.GameObjects.Sprite {
  constructor(scene, x, y) {
    super(scene, x, y, 'tankall');

    this.scene = scene;
    this.frameIndex = 0;
    this.frameTime = 0;
    this.totalFrames = 4;
    this.frameDuration = 0.1;
    this.setOrigin(0, 0);

    this.setCrop(0, 160, 66, 66);
    this.setDisplaySize(32, 32);

    scene.add.existing(this);
    scene.explosions.add(this);
  }

  update(dt) {
    this.frameTime += dt;
    if (this.frameTime >= this.frameDuration) {
      this.frameTime = 0;
      this.frameIndex++;
      if (this.frameIndex >= this.totalFrames) {
        this.destroy();
      } else {
        this.setCrop(this.frameIndex * 66, 160, 66, 66);
      }
    }
  }
}

// ✅ 将类暴露到全局
window.Explosion = Explosion;
